<?php
if(isset($_GET['id']) && isset($_GET['page']))
{	session_start();
	$id = $_GET['id'];
	$page = $_GET['page'];
	include_once("../DataProvider.php");
	if($id == 0)
	{
		$sql = "select * from tbl_games";
	}
	else
	{
		$sql = "select * from tbl_games where CategoriesID = $id";
	}
	$result = DataProvider::ExecuteQuery($sql);

	$tongsorecord = mysql_num_rows($result);
	$y = 50;
	$tongsotrang = ceil($tongsorecord/$y);
	if($page > $tongsotrang)
	{
		$page = $tongsotrang;
	}
	$start = ($page-1)*$y;
	
	if($tongsorecord == 0){
		echo "<span class='text5'>Không có game nào!</span>";	
	}else{
	?>
    <div class="groupGame">
   <table width="760">
   <tr>
   <td>
    <?php
		$stt = 0;
		if($id ==0)
		{
			$sql1 = "select * from tbl_games order by GameName limit $start,$y";
		}
		else
		{
			$sql1 = "select * from tbl_games where CategoriesID = $id order by GameName limit $start,$y";
		}
		
		$result1 = DataProvider::ExecuteQuery($sql1);
		while($data1 = mysql_fetch_array($result1)){
						?>
	<div class="pic" >
  
     <div  class="div<?php echo "1_".$data1["GameID"]?>" style="background: url(<?php echo $data1["Artwork"]?>)no-repeat; float:left; margin-left:15px; margin-top:5px; background-size:100px 100px;">
	<img onmouseout="javascript:mouseout(this)" onmouseover="javascript:mouseover(this)" id="img<?php echo "1_".$data1["GameID"] ?>" class="<?php if(isset($_SESSION['listGame']))
	 { 
	 	if(in_array($data1['GameID'],$_SESSION['listGame']))
		{
			echo 'Selected';
			
			}
			else
			{
				echo 'unSelect';
			}
		
		
	 }else echo 'unSelect';
	 ?>" alt="<?php echo $data1['GameName']; ?>" src="<?php if(isset($_SESSION['listGame']))
	 { 
	 	if(in_array($data1['GameID'],$_SESSION['listGame']))
		{
			echo 'img/mask175_check.png';
			
			}
			else
			{
				echo 'img/mask175_2.png';
			}
		
		
	 }else echo 'img/mask175_2.png';
	 ?>" height="100px" width="100px" style=" cursor: pointer;" onclick="javascript:add(this);" />
    </div>
    

   <div  class="textGame" title="<?php echo $data1['GameName']?>" ><span style="cursor:pointer;" onclick="javascript:loadScreenShoot('<?php echo $data1["GameID"]  ?>')">
    <?php 
   $tengame = "";
    if(strlen($data1["GameName"])>15)
    {
        $tengame = substr($data1["GameName"],0,15)."...";}
    else{ 
    $tengame = $data1["GameName"];} echo $tengame; ?>
    </span>
    <br />  <span style="color:#C33; font-size:12px"><?php echo number_format($data1["Price"], 0, '.', ','); ?> 
    </span>VNĐ&nbsp;&nbsp;<span style="color:#666;"><?php if($data1["Size"]>1000)	
	 		echo number_format($data1["Size"]/1000,2,".",","). " GB"; 
		else
			echo number_format($data1["Size"],2,".",",") . " MB";?>
    </span>
    </div>
    <div>
     <span style="font-size:13px; color:#FFFBF0;" title="<?php echo $data1["Notes"];  ?>"><?php echo substr($data1["Notes"],0,35)."..."; ?></span>
    </div></div>  
</div>

	<?php	}
	?>


       </td></tr><tr align="right"><td><div class="pagenav"><table cellpadding="3" cellspacing="1" border="0" style="background: none repeat scroll 0 0 #FFFFFF;
    border: 1px solid #B0BDC6;
    color: #000000; margin-right:20px;"><tr><td class="vbmenu_control">Trang <?php echo $page."/".$tongsotrang; ?>&nbsp;</td>
        <?php
        if($page == 1)
				{echo"<td class='alt2'><< Đầu </td>";}
				else
				{
				echo"<td class='alt1'><a style='text-decoration:none;' href='#1' onclick='javascript:loadGame($id,1);'><< Đầu </a> </td>";}
				if($page-3>0)
				$i = $page-3;
				else
				$i = 1;
			for($i;$i<=$tongsotrang;$i++)
			{
				if($tongsotrang < 5)
				{
					if($i == $page)
					{
					 echo "<td class='alt2'>$i</td>";	
					}
					else
					{
						echo "<td class='alt1'><a style='text-decoration:none;' href='#$i' onclick='javascript:loadGame($id,$i);'> $i</a>  </td>";	
					}
				}
				else
				{
					if($i<$page+4)
					{
						if($i == $page)
						{
						 echo "<td class='alt2'>$i</td>";	
						}
						else
						{
							echo "<td class='alt1'><a style='text-decoration:none;' href='#$i' onclick='javascript:loadGame($id,$i);'> $i</a>  </td>";	
						}
					}
					else
					{
						echo "<td class='alt1'>...</td>";	
						$temp = $i * 5;
						if( $temp <= $tongsotrang)
						{
							if($temp == $page)
							{
								 echo "<td class='alt2'> $temp </td>";
							}
							else
							 echo "<td class='alt1'><a style='text-decoration:none;' href='$temp' onclick='javascript:loadGame($id,$temp);'> $temp</a>  </td>";
							
							  break;
						}
						else
						{
							if($tongsotrang == $page)
							{
								 echo "<td class='alt2'> $tongsotrang </td>";
							}
							else
							 echo "<td class='alt1'><a style='text-decoration:none;' href='#$tongsotrang' onclick='javascript:loadGame($id,$tongsotrang);'> $tongsotrang</a>  </td>";
							
							  break;
							
						}
					}
				}
			}
			if($page == $tongsotrang)
				{echo"<td class='alt2'> Cuối >></td>";}
				else
				{
				echo"<td class='alt1' ><a style='text-decoration:none;' href='#$tongsotrang' onclick='javascript:loadGame($id,$tongsotrang);'> Cuối >> </a></td>";
				}
}}?><td style="cursor: pointer;" id="pagenav.37" class="vbmenu_control" title="" > <img border="0" alt="" title="" src="images/menu_open.gif" onclick="showgopage()"><div class="vbmenu_popup" id="pagenav_menu" style="position: absolute; z-index: 999999; clip: rect(auto, auto, auto, auto); display: none;">
		<table cellspacing="1" cellpadding="4" border="0">
		<tbody><tr>
			<td nowrap="nowrap" class="thead" style="background-color:#5C7099;">Go to Page...</td>
		</tr>
		<tr>
			<td class="vbmenu_option" title="">
			<form action="javascript:loadGame(0,document.gopage.go.value)" method="get" onsubmit="return checkgo();" id="pagenav_form" name="gopage">
				<input type="text" class="bginput" id="pagenav_itxt" name="go" style="font-size:11px" size="4">
				<input type="submit" class="button1" id="pagenav_ibtn" value="Go">
			</form>
			</td>
		</tr>
		</tbody></table>
	</div></td>
</tr></table></div>
</td></tr></table></div>
